Skip to content

fix(crag): CRAG 重放前丢掉历史里没有可用签名的 thinking 块,避免每轮 Invalid signature 400 - #1108

Closed
panjinhe wants to merge 1 commit into
dofastted:mainfrom
panjinhe:fix/crag-drop-unsigned-thinking
Closed

panjinhe wants to merge 1 commit into
dofastted:mainfrom
panjinhe:fix/crag-drop-unsigned-thinking

Conversation

@panjinhe

Copy link
Copy Markdown
Contributor

问题

CRAG print 路径(prepareCragPrintBody)不经过 stripInvalidThinkingBlocks,历史里的 thinking 块会原样交给 CRAG 重放。如果历史里有 signature: "" 的 thinking 块,上游每轮都返回 400:

messages.126.content.0: Invalid `signature` in `thinking` block
  • 生产实例:一个 Claude Code 会话先在一个不出真签名的中转渠道上(thinking 有文本、签名为空)聊出约 170 条消息,然后切到 CRAG 槽。历史里有 3 个空签名的 thinking 块。
  • 每轮先 400,客户端去掉 thinking 后重试才成功(x-stainless-retry-count: 1)。每轮多一次失败、多约 4s,面板里全是 400。
  • cli-node / HTTP 路径会被 stripInvalidThinkingBlocks 丢掉空签名块,不受影响。

改动

prepareCragPrintBody 开头调用新的 dropUnsignedHistoryThinking:

  • assistant 历史里签名不可用的 thinking 块(空、短于 24、dummy,复用 hasUsableThinkingSignature)直接删掉,和 Claude Code 自己重试时的做法一致。
  • 有签名的 thinking 和 redacted_thinking 一律不动(CRAG 内核会对已发出的流做指纹,不能改写)。
  • 如果删完会让某条 assistant 消息变空,这条消息保持原样。
  • 没有需要删的块时返回原数组,调用方 body 不被修改。

验证

  • 生产那条失败请求的出站 body 跑补丁:12 个 thinking 块里 3 个空签名被删,9 个有签名块逐字节不变。
  • 已在生产 1.4.090 以补丁形式上线。
  • test/unit/crag-print-prompt.test.mjs、anthropic-policy.test.mjs、thinking-owner.test.mjs:76/76 通过;新增 2 个用例。
  • npm run test:unit:7/379 个文件失败,和干净的 upstream/main(ab51de06)完全相同(授权 / 激活相关),与本改动无关。
  • biome format 通过。

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T04:50:26.039678Z cb345ad PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

CRAG print bypasses stripInvalidThinkingBlocks, so a history thinking block
with an empty signature (e.g. carried over from a relay that never signs) went
upstream verbatim and drew 400 "Invalid `signature` in `thinking` block" on
every turn. Drop blocks without a usable signature; signed blocks untouched.
@dofastted

Copy link
Copy Markdown
Owner

感谢复现。CRAG 3.1.4 标准版已发布;内核在原生出站过滤混合 assistant 历史中缺失、空或纯空白签名的 thinking。官方 Claude Code 2.1.321 + 本地假上游回环覆盖了空签名场景。有签名及 redacted thinking 不改,仅有 thinking 的回合保留。该版本不会仅凭长度或 dummy 判定非空签名无效,因此这里保留开放,不把额外启发式视为已覆盖。见 Release 与 #1160。

@dofastted

Copy link
Copy Markdown
Owner

关闭:本 PR 报告的混合 assistant 历史空签名 400 已由 CRAG 3.1.4 原生修复(dofastted/crag@a5d929f5af80b057b3656f8f6ec1382fbaaa369d),默认载荷已通过 #1160 进入 main。旧槽需显式安装新版。面板不采用按长度或 dummy 值删除非空签名的额外规则;非空外来签名另见 #1149。

@dofastted dofastted closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants